<template>
    <div class="singer-wrap">
        <van-nav-bar title="pulldown-refresh" left-text="返回"  left-arrow @click-left="onClickLeft"/>
        <div class="pulldown-wrapper">
            <scroll ref="scroll" :pullDownRefresh="pullDownRefresh"  @pulling-down="pullingDown">
                <ul class="pulldown-list">
                    <li v-for="i of dataList" :key="i" class="list-item">
                        <van-cell :title="'I am item'+i" />
                    </li>
                </ul>
            </scroll>
        </div>
    </div>
</template>

<script>
import Scroll from 'components/scroll/scroll'

let STEP = 0
function getOneRandomList(step = 0) {
const arr = Array.apply(null, {length: (30 + step)}).map((...args) => args[1])
return arr.sort(() => Math.random() - 0.5)
}
export default {
    name:'',
    data(){
        return {
            dataList: getOneRandomList(),
            pullDownRefresh: {
                threshold: 50,
                stop: 40
            }
        }
    },
    mounted() {

    },
    methods: {
        onClickLeft() {
            this.$router.back()
            console.log('ma pipi')
            console.log('test mapiqiang')
            console.log('20220503')
        },
        async pullingDown(){
            STEP += 10
            await this.requestData()
            this.$refs.scroll.finishPullDown()
        },
        async requestData() {
            try {
                const newData = await this.ajaxGet(/* url */)
                this.dataList = newData
            } catch (err) {
                console.log(err)
            }
        },
        ajaxGet(/* url */) {
            return new Promise(resolve => {
                setTimeout(() => {
                    const dataList = getOneRandomList(STEP)
                    resolve(dataList)
                }, 1000)
            })
        }
    },
    components: {
        Scroll
    }
}
</script>

<style scoped lang="less">
    .singer-wrap{
        overflow: hidden;
        position: fixed;
        top: 0;
        bottom: 0;
        width: 100%;
        background: #fff;
        /deep/ .van-nav-bar__text, .van-icon{
            color: #333 !important;
        }
        .pulldown-wrapper{
            position: absolute;
            top: 46px;
            bottom: 0;
            width: 100%;
            .pulldown-list{
                padding: 0;
                .list-item{
                    padding: 10px 20px;
                    list-style: none;
                    background:#fff;
                }
            }
            .pulldown-wrapper{
                position: absolute;
                width: 100%;
                padding: 10px;
                box-sizing: border-box;
                transform: translateY(-100%) translateZ(0);
                text-align: center;
                color: #999;
                .awrrow{
                    transition: transform .3s;
                    transform:rotateZ(0deg);
                    font-size: 20px;
                    &.awrrow-down{
                        transform:rotateZ(180deg);
                    }
                }
            }
        }
    }


</style>
